/*
 * SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
 *
 * SPDX-License-Identifier: MulanPSL-2.0
 */
#![allow(
    non_camel_case_types,
    non_snake_case,
    non_upper_case_globals,
    unused_macros,
    dead_code
)]

////////////  调用其它模块中接口
pub use crate::sudo_debug::*;
pub use libc::abort;
pub use libc::dirfd;
pub use libc::free;
pub use libc::getpid;
pub use libc::madvise;
pub use libc::malloc;
pub use libc::pthread_atfork;
pub use libc::raise;
pub use libc::DIR;
pub use std::ffi::CStr;
pub use std::ffi::CString;
pub use std::string::String;

////////////  调用第三方库函数

////////////  定义类型
pub type nfds_t = libc::c_ulong;
pub type pid_t = __pid_t;
pub type size_t = libc::c_ulong;
pub type __off_t = libc::c_long;
pub type __ino_t = libc::c_ulong;
pub type __uint64_t = libc::c_ulong;
pub type uint64_t = __uint64_t;
pub type __uint32_t = libc::c_uint;
pub type uint32_t = __uint64_t;
pub type __uint8_t = libc::c_uchar;
pub type uint8_t = __uint8_t;
pub type __time_t = libc::c_long;
pub type __syscall_slong_t = libc::c_long;
pub type __dev_t = libc::c_ulong;
pub type dev_t = __dev_t;
pub type __uid_t = libc::c_uint;
pub type __gid_t = libc::c_uint;
pub type __mode_t = libc::c_uint;

#[cfg(target_arch = "x86_64")]
pub type __nlink_t = libc::c_ulong;
#[cfg(not(target_arch = "x86_64"))]
pub type __nlink_t = libc::c_uint;

#[cfg(target_arch = "x86_64")]
pub type __blksize_t = libc::c_long;
#[cfg(not(target_arch = "x86_64"))]
pub type __blksize_t = libc::c_int;

pub type __off64_t = libc::c_long;
pub type __blkcnt_t = libc::c_long;
pub type __ssize_t = libc::c_long;
pub type gid_t = __gid_t;
pub type uid_t = __uid_t;
pub type ssize_t = __ssize_t;
pub type __pid_t = libc::c_int;
pub type __clock_t = libc::c_long;
pub type __suseconds_t = libc::c_long;
pub type __sig_atomic_t = libc::c_int;
pub type sig_atomic_t = __sig_atomic_t;
pub type time_t = __time_t;
pub type __id_t = libc::c_uint;
pub type id_t = __id_t;
pub type __clockid_t = libc::c_int;
pub type clockid_t = __clockid_t;
pub type off_t = __off_t;
pub type __int32_t = libc::c_int;
pub type FILE = _IO_FILE;
pub type u8 = libc::c_uchar;
pub type u32 = libc::c_uint;
pub type mode_t = __mode_t;
pub type in_addr_t = libc::c_uint;
pub type _IO_lock_t = ();

pub type sudo_conv_callback_fn_t =
    Option<unsafe extern "C" fn(libc::c_int, *mut libc::c_void) -> libc::c_int>;

pub type sudo_conv_t = Option<
    unsafe extern "C" fn(
        libc::c_int,
        *const sudo_conv_message,
        *mut sudo_conv_reply,
        *mut sudo_conv_callback,
    ) -> libc::c_int,
>;

pub type sudo_hook_fn_t = Option<unsafe extern "C" fn() -> libc::c_int>;

pub type sudo_printf_t =
    Option<unsafe extern "C" fn(libc::c_int, *const libc::c_char, ...) -> libc::c_int>;

pub type sudo_fatal_callback_t = Option<unsafe extern "C" fn()>;

////////////  定义静态变量值
pub const EINVAL: libc::c_int = 22;
pub const SHA512_BLOCK_LENGTH: usize = 128;
pub const __SIGRTMIN: libc::c_uint = 64;
pub const NSIG: libc::c_uint = __SIGRTMIN + 1;
pub const _SC_NGROUPS_MAX: libc::c_uint = 3;
pub const _SC_OPEN_MAX: i32 = 4;
pub const SIZE_MAX: libc::c_ulong = 18446744073709551615;
pub const RSIZE_MAX: libc::c_ulong = SIZE_MAX >> 1;
pub const NGROUPS_MAX: libc::c_uint = 65536;
pub const SUDO_PATH_SECURE: libc::c_int = 0;
pub const SUDO_PATH_MISSING: libc::c_int = -1;
pub const SUDO_PATH_BAD_TYPE: libc::c_int = -2;
pub const SUDO_PATH_WRONG_OWNER: libc::c_int = -3;
pub const SUDO_PATH_WORLD_WRITABLE: libc::c_int = -4;
pub const SUDO_PATH_GROUP_WRITABLE: libc::c_int = -5;
pub const ENOENT: libc::c_int = 2;
pub const _SC_RTSIG_MAX: libc::c_int = 31;
pub const _ISdigit: libc::c_uint = 2048;
pub const ERANGE: libc::c_int = 34;
pub const _ISspace: libc::c_uint = 8192;
pub const SUDO_DEBUG_CRIT: libc::c_int = 1;
pub const SUDO_DEBUG_ERROR: libc::c_int = 2;
pub const SUDO_DEBUG_WARN: libc::c_int = 3;
pub const SUDO_DEBUG_NOTICE: libc::c_int = 4;
pub const SUDO_DEBUG_DIAG: libc::c_int = 5;
pub const SUDO_DEBUG_INFO: libc::c_int = 6;
pub const SUDO_DEBUG_TRACE: libc::c_int = 7;
pub const SUDO_DEBUG_DEBUG: libc::c_int = 8;
pub const SUDO_DEBUG_ERRNO: libc::c_int = 1 << 4;
pub const SUDO_DEBUG_LINENO: libc::c_int = 1 << 5;
pub const SUDO_DEBUG_ARGS: libc::c_int = 1 << 6;
pub const SUDO_DEBUG_CONV: libc::c_int = 2 << 6;
pub const SUDO_DEBUG_EDIT: libc::c_int = 3 << 6;
pub const SUDO_DEBUG_EVENT: libc::c_int = 4 << 6;
pub const SUDO_DEBUG_EXEC: libc::c_int = 5 << 6;
pub const SUDO_DEBUG_HOOKS: libc::c_int = 6 << 6;
pub const SUDO_DEBUG_MAIN: libc::c_int = 7 << 6;
pub const SUDO_DEBUG_NETIF: libc::c_int = 8 << 6;
pub const SUDO_DEBUG_PCOMM: libc::c_int = 9 << 6;
pub const SUDO_DEBUG_PLUGIN: libc::c_int = 10 << 6;
pub const SUDO_DEBUG_PTY: libc::c_int = 11 << 6;
pub const SUDO_DEBUG_SELINUX: libc::c_int = 12 << 6;
pub const SUDO_DEBUG_UTIL: libc::c_int = 13 << 6;
pub const SUDO_DEBUG_UTMP: libc::c_int = 14 << 6;
pub const SUDO_DEBUG_INSTANCE_ERROR: libc::c_int = -2;
pub const SUDO_DEBUG_INSTANCE_INITIALIZER: libc::c_int = -1;
pub const ROOT_UID: libc::c_int = 0 as libc::c_int;
pub const GROUP_API_VERSION_MAJOR: libc::c_int = 1 as libc::c_int;
pub const GROUP_API_VERSION_MINOR: libc::c_int = 0 as libc::c_int;
pub const SUDO_CONV_PROMPT_ECHO_OFF: libc::c_int = 0x0001;
pub const SUDO_CONV_PROMPT_ECHO_ON: libc::c_int = 0x0002;
pub const SUDO_CONV_ERROR_MSG: libc::c_int = 0x0003;
pub const SUDO_CONV_INFO_MSG: libc::c_int = 0x0004;
pub const SUDO_CONV_PROMPT_MASK: libc::c_int = 0x0005;
pub const SUDO_CONV_PROMPT_ECHO_OK: libc::c_int = 0x1000;
pub const SUDO_CONV_PREFER_TTY: libc::c_int = 0x2000;
pub const EOF: libc::c_int = -1;
pub const EPROTONOSUPPORT: libc::c_int = 93;
pub const EAFNOSUPPORT: libc::c_int = 97;
pub const AUDIT_NOT_CONFIGURED: libc::c_int = -2;
pub const AUDIT_USER_CMD: libc::c_int = 1123;
pub const ECONNREFUSED: libc::c_int = 111;
pub const F_SETFD: libc::c_int = 2;
pub const FD_CLOEXEC: libc::c_int = 1;
pub const LC_ALL: libc::c_int = 6;

pub static mut sudo_debug_subsys: libc::c_int = 0 as libc::c_int;

pub const MODE_EDIT: libc::c_int = 0x00000002; // 2
pub const MODE_LOGIN_SHELL: libc::c_int = 0x00040000;
pub const MODE_BACKGROUND: libc::c_int = 0x00010000;
pub const MODE_SHELL: libc::c_int = 0x00020000;
pub const MODE_IMPLIED_SHELL: libc::c_int = 0x00080000;
pub const MODE_RESET_HOME: libc::c_int = 0x00100000;
pub const MODE_PRESERVE_GROUPS: libc::c_int = 0x00200000;
pub const MODE_PRESERVE_ENV: libc::c_int = 0x00400000;
pub const MODE_NONINTERACTIVE: libc::c_int = 0x00800000;
pub const MODE_LONG_LIST: libc::c_int = 0x01000000;

pub const SUDO_HOOK_VERSION_MAJOR: libc::c_uint = 1;
pub const SUDO_HOOK_VERSION_MINOR: libc::c_uint = 0;

pub const SUDO_HOOK_SETENV: libc::c_uint = 1;
pub const SUDO_HOOK_UNSETENV: libc::c_uint = 2;
pub const SUDO_HOOK_PUTENV: libc::c_uint = 3;
pub const SUDO_HOOK_GETENV: libc::c_uint = 4;

pub const SUDOERS_GRAMMAR_VERSION: libc::c_int = 5;
// #define SUDOERS_GRAMMAR_VERSION	46

pub const MODE_RUN: libc::c_int = 0x00000001; // 1
pub const MODE_VALIDATE: libc::c_int = 0x00000004; // 4
pub const MODE_INVALIDATE: libc::c_int = 0x00000008; // 8
pub const MODE_KILL: libc::c_int = 0x00000010; // 16
pub const MODE_VERSION: libc::c_int = 0x00000020; // 32
pub const MODE_HELP: libc::c_int = 0x00000040; // 64
pub const MODE_LIST: libc::c_int = 0x00000080; // 128
pub const MODE_CHECK: libc::c_int = 0x00000100; // 256
pub const MODE_MASK: libc::c_int = 0x0000ffff; //  65535

pub const MAX_UID_T_LEN: libc::c_int = 10;

pub const SUDO_API_VERSION_MAJOR: libc::c_int = 1;
pub const SUDO_API_VERSION_MINOR: libc::c_int = 13;
pub const SUDO_DSO_DEFAULT: *mut libc::c_void = -(2 as libc::c_int) as *mut libc::c_void;

pub const ELOOP: libc::c_int = 40;
pub const O_RDONLY: libc::c_int = 0o0;
pub const O_RDWR: libc::c_int = 0o2;
pub const O_CREAT: libc::c_int = 0o100;
pub const EAGAIN: libc::c_int = 11;
pub const EWOULDBLOCK: libc::c_int = 11;
pub const S_ISVTX: libc::c_int = 0o1000;
pub const S_ISGID: libc::c_int = 0o2000;
pub const S_ISUID: libc::c_int = 0o4000;

//#define SEEK_SET	0	/* Seek from beginning of file.  */
//#define SEEK_END	2	/* Seek from end of file.  */
pub const SEEK_SET: libc::c_int = 0;
pub const SEEK_END: libc::c_int = 2;

pub const __S_IREAD: libc::c_int = 0o400;
pub const __S_IWRITE: libc::c_int = 0o200;
pub const __S_IEXEC: libc::c_int = 0o100;
pub const S_IRWXU: libc::c_int = __S_IREAD | __S_IWRITE | __S_IEXEC;
pub const S_IXUSR: libc::c_int = 0o100;
pub const S_IXGRP: libc::c_int = S_IXUSR >> 3;
pub const S_IXOTH: libc::c_int = S_IXGRP >> 3;

pub const S_IRWXG: libc::c_int = S_IRWXU >> 3;
pub const S_IRWXO: libc::c_int = S_IRWXG >> 3;
pub const S_IREAD: libc::c_int = 0o400;
pub const S_IWRITE: libc::c_int = 0o200;

pub const SIG2STR_MAX: libc::c_int = 32;
pub const SIGALRM: libc::c_int = 14;
pub const SIGBUS: libc::c_int = 10;
pub const SIGCHLD: libc::c_int = 17;
pub const SIGCONT: libc::c_int = 18;
pub const SIGCONT_BG: libc::c_int = -3;
pub const SIGCONT_FG: libc::c_int = -2;
pub const SIGHUP: libc::c_int = 1;
pub const SIGINT: libc::c_int = 2;
pub const SIGKILL: libc::c_int = 9;
pub const SIGPIPE: libc::c_int = 13;
pub const SIGQUIT: libc::c_int = 3;
pub const SIGSTOP: libc::c_int = 19;
pub const SIGSYS: libc::c_int = 12;
pub const SIGTERM: libc::c_int = 15;
pub const SIGTRAP: libc::c_int = 5;
pub const SIGTSTP: libc::c_int = 20;
pub const SIGTTIN: libc::c_int = 21;
pub const SIGTTOU: libc::c_int = 22;
pub const SIGUSR1: libc::c_int = 10;
pub const SIGUSR2: libc::c_int = 12;
pub const SIGWINCH: libc::c_int = 28;
pub const SIG_BLOCK: libc::c_int = 0;
pub const SIG_SETMAS: libc::c_int = 2;
pub const SIG_SETMASK: libc::c_int = 2;
pub const SIG_UNBLOCK: libc::c_int = 1;
pub const SA_RESTART: libc::c_int = 0x10000000;
pub const EINTR: libc::c_int = 4;
pub const SUDO_CONF_DEBUG: libc::c_int = 0x01;
pub const SUDO_CONF_PLUGINS: libc::c_int = 0x04;

// #  define AT_FDCWD	-100
pub const AT_FDCWD: libc::c_int = -100;

pub const EACCES: libc::c_int = 13;
pub const ENOTDIR: libc::c_int = 20;
pub const SUDO_LOCK: libc::c_int = 1;
pub const SUDO_TLOCK: libc::c_int = 2;
pub const SUDO_UNLOCK: libc::c_int = 4;
pub const SUDO_CONV_REPL_MAX: libc::c_int = 255;

//#define	__S_IFIFO	0010000	/* FIFO.  */
pub const __S_IFIFO: libc::c_int = 0o010000;
pub const _ISblank: libc::c_int = 1;

////////////  定义宏
#[macro_export]
macro_rules! SUDO_API_VERSION {
    () => {
        SUDO_API_MKVERSION!(SUDO_API_VERSION_MAJOR, SUDO_API_VERSION_MINOR)
    };
}

#[macro_export]
macro_rules! INT_MAX {
    () => {
        0x7fffffff
    };
}

#[macro_export]
macro_rules! _S_IFMT {
    () => {
        0o170000
    };
}

#[macro_export]
macro_rules! S_IWUSR {
    () => {
        0o200
    };
}
// #define	S_IWGRP	(S_IWUSR >> 3)	/* Write by group.  */
#[macro_export]
macro_rules! S_IWGRP {
    () => {
        S_IWUSR!() >> 3
    };
}

// #define	S_IWOTH	(S_IWGRP >> 3)	/* Write by others.  */
#[macro_export]
macro_rules! S_IWOTH {
    () => {
        S_IWGRP!() >> 3
    };
}

// #define ISSET(t, f)     ((t) & (f))
#[macro_export]
macro_rules! ISSET {
    ($_t:expr, $_f:expr) => {
        (($_t) & ($_f))
    };
}

/* Extract subsystem number and convert to an index. */
// #define SUDO_DEBUG_SUBSYS(n) (((n) >> 6) - 1)
#[macro_export]
macro_rules! SUDO_DEBUG_SUBSYS {
    ($_n:expr) => {
        ((($_n) >> 6) - 1)
    };
}

/* Extract priority number and convert to an index. */
// #define SUDO_DEBUG_PRI(n) (((n) & 0x0f) - 1)
#[macro_export]
macro_rules! SUDO_DEBUG_PRI {
    ($_n:expr) => {
        ((($_n) & 0x0f) - 1)
    };
}

// #define TIOCGWINSZ	0x5413
#[macro_export]
macro_rules! TIOCGWINSZ {
    () => {
        0x5413
    };
}

#[macro_export]
macro_rules! _POSIX_OPEN_MAX {
    () => {
        20
    };
}

// #define	__S_IFREG	0100000	/* Regular file.  */
#[macro_export]
macro_rules! _S_IFREG {
    () => {
        0o100000
    };
}

// #define	__S_IFDIR	0040000	/* Directory.  */
#[macro_export]
macro_rules! _S_IFDIR {
    () => {
        0o40000
    };
}

// #define INT_MIN (-__INT_MAX__ - 1)
#[macro_export]
macro_rules! INT_MIN {
    () => {
        (-(INT_MAX!()) - 1)
    };
}

// #define UINT_MAX (__INT_MAX__ * 2U + 1U)
#[macro_export]
macro_rules! UINT_MAX {
    () => {
        ((INT_MAX!()) * (2 as libc::c_uint) + 1 as libc::c_uint)
    };
}

// #define isblank(c)	__isctype((c), _ISblank)
#[macro_export]
macro_rules! isblank {
    ($c:expr) => {
        __isctype!($c, _ISblank)
    };
}

// # define __isctype(c, type)  ((*__ctype_b_loc ())[(int) (c)] & (unsigned short int) type)
#[macro_export]
macro_rules! __isctype {
    ($c:expr, $type:expr) => {
        (*(*__ctype_b_loc()).offset($c as isize) as libc::c_int)
            & ($type as libc::c_int as libc::c_ushort as libc::c_int)
    };
}

// define _ISbit(bit)	((bit) < 8 ? ((1 << (bit)) << 8) : ((1 << (bit)) >> 8))
//   _ISblank = _ISbit (8),	/* Blank (usually SPC and TAB).  */
#[macro_export]
macro_rules! _ISbit {
    ($bit:expr) => {
        if ($bit) < 8 {
            ((1 << ($bit)) << 8)
        } else {
            ((1 << ($bit)) >> 8)
        }
    };
}

#[macro_export]
macro_rules! _ISblank {
    () => {
        _ISbit!(8)
    };
}

macro_rules! SUDO_DEBUG_ALL {
    /* all subsystems */
    () => {
        0xffff0000
    };
}

#[macro_export]
macro_rules! debug_decl_func {
    ($funcname:expr) => {};
}

#[macro_export]
macro_rules! debug_decl_vars {
    ($subsys:expr) => {
        sudo_debug_subsys = $subsys
    };
}

#[macro_export]
macro_rules! debug_decl {
    ($subsys:expr) => {
        debug_decl_vars!($subsys);
        sudo_debug_enter_v1(
            get_function_name!(),
            get_file_name!(),
            line!() as libc::c_int,
            sudo_debug_subsys as libc::c_int,
        );
    };
}

#[macro_export]
macro_rules! debug_return_int {
    ($ret:expr) => {{
        let mut tmp_var: libc::c_int = $ret as libc::c_int;
        sudo_debug_exit_int_v1(
            get_function_name!(),
            get_file_name!(),
            line!() as libc::c_int,
            sudo_debug_subsys as libc::c_int,
            tmp_var,
        );
        return tmp_var;
    }};
}

#[macro_export]
macro_rules! debug_return_id_t {
    ($ret:expr) => {{
        sudo_debug_exit_id_t_v1(
            get_function_name!(),
            get_file_name!(),
            line!() as libc::c_int,
            sudo_debug_subsys as libc::c_int,
            $ret,
        );
        return $ret;
    }};
}

#[macro_export]
macro_rules! debug_return_size_t {
    ($ret:expr) => {
        sudo_debug_exit_size_t_v1(
            get_function_name!(),
            get_file_name!(),
            line!() as libc::c_int,
            sudo_debug_subsys as libc::c_int,
            $ret,
        );
        return $ret;
    };
}

#[macro_export]
macro_rules! debug_return_ssize_t {
    ($ret:expr) => {{
        sudo_debug_exit_ssize_t_v1(
            get_function_name!(),
            get_file_name!(),
            line!() as libc::c_int,
            sudo_debug_subsys as libc::c_int,
            $ret,
        );
        return $ret;
    }};
}

#[macro_export]
macro_rules! debug_return_time_t {
    ($ret:expr) => {{
        sudo_debug_exit_time_t_v1(
            get_function_name!(),
            get_file_name!(),
            line!() as libc::c_int,
            sudo_debug_subsys as libc::c_int,
            $ret,
        );
        return $ret;
    }};
}

#[macro_export]
macro_rules! debug_return_long {
    ($ret:expr) => {
        sudo_debug_exit_long(
            get_function_name!(),
            get_file_name!(),
            line!(),
            sudo_debug_subsys,
            $ret,
        );
        return $ret;
    };
}

#[macro_export]
macro_rules! debug_return_bool {
    ($ret:expr) => {{
        let mut tmp_var: bool = $ret as bool;
        sudo_debug_exit_bool_v1(
            get_function_name!(),
            get_file_name!(),
            line!() as libc::c_int,
            sudo_debug_subsys as libc::c_int,
            tmp_var,
        );
        return tmp_var;
    }};
}

#[macro_export]
macro_rules! debug_return_str {
    ($ret:expr) => {{
        sudo_debug_exit_str_v1(
            get_function_name!(),
            get_file_name!(),
            line!() as libc::c_int,
            sudo_debug_subsys as libc::c_int,
            $ret,
        );
        return $ret;
    }};
}

#[macro_export]
macro_rules! debug_return_const_str {
    ($ret:expr) => {{
        sudo_debug_exit_str_v1(
            get_function_name!(),
            get_file_name!(),
            line!() as libc::c_int,
            sudo_debug_subsys as libc::c_int,
            $ret as *const libc::c_char,
        );
        return $ret as *const libc::c_char;
    }};
}

#[macro_export]
macro_rules! debug_return_str_masked {
    ($ret:expr) => {{
        sudo_debug_exit_str_masked_v1(
            get_function_name!(),
            get_file_name!(),
            line!() as libc::c_int,
            sudo_debug_subsys as libc::c_int,
            $ret,
        );
        return $ret;
    }};
}

#[macro_export]
macro_rules! debug_return_ptr {
    ($ret:expr) => {{
        sudo_debug_exit_ptr_v1(
            get_function_name!(),
            get_file_name!(),
            line!() as libc::c_int,
            sudo_debug_subsys as libc::c_int,
            $ret as *const libc::c_void,
        );
        return $ret;
    }};
}

macro_rules! debug_return_const_ptr {
    ($ret:expr) => {{
        sudo_debug_exit_ptr_v1(
            get_function_name!(),
            get_file_name!(),
            line!() as libc::c_int,
            sudo_debug_subsys as libc::c_int,
            $ret as *const libc::c_void,
        );
        return $ret;
    }};
}

#[macro_export]
macro_rules! sudo_debug_execve {
    ($pri:expr, $path:expr, $argv:expr, $envp:expr) => {{
        sudo_debug_execve2_v1(
            $pri | sudo_debug_subsys as libc::c_int,
            $path as *const libc::c_char,
            $argv as *const *mut libc::c_char,
            $envp as *const *mut libc::c_char,
        );
    }};
}

// #define sudo_debug_write(fd, str, len, errnum) \
//     sudo_debug_write2(fd, NULL, NULL, 0, (str), (len), (errnum))

macro_rules! sudo_debug_write {
    ($fd:expr, $str:expr, $len:expr, $errnum:expr) => {{
        sudo_debug_write2_v1(
            $fd as libc::c_int,
            0 as *const libc::c_char,
            0 as *const libc::c_char,
            0 as libc::c_int,
            $str as *const libc::c_char,
            $len as libc::c_int,
            $errnum as libc::c_int,
        );
    }};
}

// # define sudo_debug_printf(pri, ...) \
//     sudo_debug_printf2(__func__, __FILE__, __LINE__, (pri)|sudo_debug_subsys, \
//     __VA_ARGS__)
// #endif
#[macro_export]
macro_rules! sudo_debug_printf {
    ($pri:expr, $($arg:tt)*) => {{
    sudo_debug_printf2_v1(
        get_function_name!(),
        get_file_name!(),
        line!() as libc::c_int,
        ($pri | sudo_debug_subsys) as libc::c_int,
        $($arg)*,
        );
    }};
}

#[macro_export]
macro_rules! debug_return {
    () => {{
        sudo_debug_exit_v1(
            get_function_name!(),
            get_file_name!(),
            line!() as libc::c_int,
            sudo_debug_subsys as libc::c_int,
        );
        return;
    }};
}

// #  define sudo_warn(fmt...) do {					       \
//     sudo_debug_printf2(__func__, __FILE__, __LINE__,			       \
// 	SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO|SUDO_DEBUG_ERRNO|sudo_debug_subsys, \
// 	fmt);								       \
//     sudo_warn_nodebug_v1(fmt);
// } while (0)
#[macro_export]
macro_rules! sudo_warn {
    ($fmt:expr, $($arg:tt)*) => {{
        sudo_debug_printf2_v1(
            get_function_name!(),
            get_file_name!(),
            line!() as libc::c_int,
            SUDO_DEBUG_WARN|SUDO_DEBUG_LINENO|SUDO_DEBUG_ERRNO|sudo_debug_subsys,
            $fmt,
            $($arg)*
            );
        sudo_warn_nodebug_v1($fmt,  $($arg)*);
    }};
}

// sudo_warnx(fmt...) do {					       \
//     sudo_debug_printf2(__func__, __FILE__, __LINE__,			       \
// 	SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO|sudo_debug_subsys, fmt);	       \
//     sudo_warnx_nodebug_v1(fmt);
// } while (0)
#[macro_export]
macro_rules! sudo_warnx {
    ($fmt:expr, $($arg:tt)*) => {{
    sudo_debug_printf2_v1(
            get_function_name!(),
            get_file_name!(),
            line!() as libc::c_int,
            SUDO_DEBUG_WARN|SUDO_DEBUG_LINENO|sudo_debug_subsys,
            $fmt,
            $($arg)*
            );
        sudo_warnx_nodebug_v1(
            $fmt,
            $($arg)*
        );
    }};
}

// #  define sudo_fatalx(fmt...) do {					       \
//     sudo_debug_printf2(__func__, __FILE__, __LINE__,			       \
// 	SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO|sudo_debug_subsys, fmt);	       \
//     sudo_fatalx_nodebug_v1(fmt);					       \
// } while (0)
#[macro_export]
macro_rules! sudo_fatalx {
    ($fmt:expr, $($arg:tt)*) => {{
    sudo_debug_printf2_v1(
            get_function_name!(),
            get_file_name!(),
            line!() as libc::c_int,
            SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO|sudo_debug_subsys,
            $fmt,
            $($arg)*
            );
        sudo_fatalx_nodebug_v1(
            $fmt,
            $($arg)*
        );
    }};
}

// #  define sudo_fatal(fmt...) do {					       \
//     sudo_debug_printf2(__func__, __FILE__, __LINE__,			       \
// 	SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO|SUDO_DEBUG_ERRNO|sudo_debug_subsys, \
// 	fmt);								       \
//     sudo_fatal_nodebug_v1(fmt);
// } while (0)
#[macro_export]
macro_rules! sudo_fatal {
    ($fmt:expr, $($arg:tt)*) => {{
        sudo_debug_printf2_v1(
            get_function_name!(),
            get_file_name!(),
            line!() as libc::c_int,
            SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO|SUDO_DEBUG_ERRNO|sudo_debug_subsys,
            $fmt,
            $($arg)*
            );
        sudo_fatal_nodebug_v1($fmt,  $($arg)*);
    }};
}

// #define CLR(t, f)	((t) &= ~(f))
#[macro_export]
macro_rules! CLR {
    ($t:expr, $f:expr) => {
        (($t) &= !($f))
    };
}

// #define SET(t, f)	((t) |= (f))
#[macro_export]
macro_rules! SET {
    ($t:expr, $f:expr) => {
        (($t) |= ($f))
    };
}

/* Standard file descriptors.  */
// #define	STDERR_FILENO	2	/* Standard error output.  */
#[macro_export]
macro_rules! STDERR_FILENO {
    () => {
        2
    };
}

// #define SIGRTMIN        (__libc_current_sigrtmin ())
#[macro_export]
macro_rules! SIGRTMIN {
    () => {
        (__libc_current_sigrtmin())
    };
}

// #define SIGRTMAX        (__libc_current_sigrtmax ())
#[macro_export]
macro_rules! SIGRTMAX {
    () => {
        (__libc_current_sigrtmax())
    };
}

/* Values for sudo_dso_load() mode. */
// #define SUDO_DSO_LAZY	 0x1
// #define SUDO_DSO_NOW	 0x2
// #define SUDO_DSO_GLOBAL	 0x4
// #define SUDO_DSO_LOCAL	 0x8
#[macro_export]
macro_rules! SUDO_DSO_LAZY {
    () => {
        0x1
    };
}

#[macro_export]
macro_rules! SUDO_DSO_NOW {
    () => {
        0x2
    };
}

#[macro_export]
macro_rules! SUDO_DSO_GLOBAL {
    () => {
        0x4
    };
}

#[macro_export]
macro_rules! SUDO_DSO_LOCAL {
    () => {
        0x8
    };
}

/* Getters and setters for plugin API versions */
// #define SUDO_API_VERSION_GET_MAJOR(v) ((v) >> 16)
// #define SUDO_API_VERSION_GET_MINOR(v) ((v) & 0xffffU)
#[macro_export]
macro_rules! SUDO_API_VERSION_GET_MAJOR {
    ($v:expr) => {
        (($v) >> 16)
    };
}

// #define SUDO_API_VERSION_GET_MINOR(v) ((v) & 0xffffU)
#[macro_export]
macro_rules! SUDO_API_VERSION_GET_MINOR {
    ($v:expr) => {
        (($v) & 0xffff)
    };
}

#[macro_export]
macro_rules! SUDO_API_MKVERSION {
    ($x: expr, $y: expr) => {
        ((($x) << 16) | ($y))
    };
}

// #define GROUP_API_VERSION SUDO_API_MKVERSION(GROUP_API_VERSION_MAJOR, GROUP_API_VERSION_MINOR)
#[macro_export]
macro_rules! GROUP_API_VERSION {
    () => {
        (SUDO_API_MKVERSION!(GROUP_API_VERSION_MAJOR, GROUP_API_VERSION_MINOR))
    };
}

// #define	_PATH_DEV	"/dev/"
#[macro_export]
macro_rules! _PATH_DEV {
    () => {
        b"/dev/\0" as *const u8 as *const libc::c_char
    };
}

#[macro_export]
macro_rules! SUDO_HOOK_VERSION {
    () => {
        SUDO_API_MKVERSION!(SUDO_HOOK_VERSION_MAJOR, SUDO_HOOK_VERSION_MINOR)
    };
}

/* Define to the version of this package. */
// #define PACKAGE_VERSION "0.0.5"
#[macro_export]
macro_rules! PACKAGE_VERSION {
    () => {
        (b"1.0.0\0" as *const u8 as *const libc::c_char)
    };
}

// # define _PATH_NSSWITCH_CONF "/etc/nsswitch.conf"
#[macro_export]
macro_rules! _PATH_NSSWITCH_CONF {
    () => {
        (b"/etc/nsswitch.conf\0" as *const u8 as *const libc::c_char)
    };
}

#[macro_export]
macro_rules! ACCESSPERMS {
    () => {
        (S_IRWXU | S_IRWXG | S_IRWXO)
    };
}

#[macro_export]
macro_rules! ALLPERMS {
    () => {
        (S_ISUID as libc::c_int
            | S_ISGID as libc::c_int
            | S_ISVTX as libc::c_int
            | S_IRWXU as libc::c_int
            | S_IRWXG as libc::c_int
            | S_IRWXO as libc::c_int)
    };
}

#[macro_export]
macro_rules! USER_SIGNALED {
    ($_info:expr) => {
        (!($_info).is_null() && (*($_info)).si_code == SI_USER)
    };
}
#[macro_export]
macro_rules! WIFSTOPPED {
    ($status:expr) => {
        ($status & 0xff == 0x7f)
    };
}
#[macro_export]
macro_rules! WIFSIGNALED {
    ($status:expr) => {
        (((($status & 0x7f) + 1) >> 1) > 0)
    };
}
#[macro_export]
macro_rules! WEXITSTATUS {
    ($status:expr) => {
        ((($status) & 0xff00) >> 8)
    };
}
#[macro_export]
macro_rules! WSTOPSIG {
    ($status:expr) => {
        ((($status) & 0xff00) >> 8)
    };
}
#[macro_export]
macro_rules! WTERMSIG {
    ($status:expr) => {
        ($status & 0x7f)
    };
}
#[macro_export]
macro_rules! WIFEXITED {
    ($status: expr) => {
        (WTERMSIG!($status) == 0)
    };
}
// #define S_IFMT  00170000
#[macro_export]
macro_rules! S_IFMT {
    () => {
        0o0170000
    };
}
// #define __S_ISTYPE(mode, mask)  (((mode) & __S_IFMT) == (mask))
#[macro_export]
macro_rules! __S_ISTYPE {
    ($mode:expr, $mask:expr) => {
        ((($mode) & S_IFMT!()) == ($mask))
    };
}
#[macro_export]
macro_rules! S_ISFIFO {
    ($mode: expr) => {
        __S_ISTYPE!(($mode), __S_IFIFO as libc::c_uint)
    };
}

#[macro_export]
macro_rules! S_IRUSR {
    () => {
        0o400
    };
}

// # define S_IRGRP    (S_IRUSR >> 3)  /* Read by group.  */
#[macro_export]
macro_rules! S_IRGRP {
    () => {
        (S_IRUSR!() >> 3)
    };
}

// #define	_PATH_TTY	"/dev/tty"
#[macro_export]
macro_rules! _PATH_TTY {
    () => {
        b"/dev/tty\0" as *const u8 as *const libc::c_char
    };
}
#[macro_export]
macro_rules! get_file_name {
    () => {
        CString::new(file!()).unwrap().as_bytes_with_nul().as_ptr() as *const libc::c_char
    };
}

#[macro_export]
macro_rules! get_function_name {
    () => {
        CString::new(stdext::function_name!())
            .unwrap()
            .as_bytes_with_nul()
            .as_ptr() as *const libc::c_char
    };
}

////////////  定义结构体值
#[derive(Copy, Clone)]
#[repr(C)]
pub struct pollfd {
    pub fd: libc::c_int,
    pub events: libc::c_short,
    pub revents: libc::c_short,
}

#[derive(Copy, Clone)]
#[repr(C)]
pub struct timespec {
    pub tv_sec: __time_t,
    pub tv_nsec: __syscall_slong_t,
}

#[derive(Copy, Clone)]
#[repr(C)]
pub struct SHA2_CTX {
    pub state: state,
    pub count: [uint64_t; 2],
    pub buffer: [uint8_t; SHA512_BLOCK_LENGTH],
}
#[derive(Copy, Clone)]
#[repr(C)]
pub union state {
    pub st32: [uint32_t; 8],
    pub st64: [uint64_t; 8],
}

#[derive(Copy, Clone)]
#[repr(C)]
pub struct sudo_event {
    pub entries: TAILQ_ENTRY_sudo_event,
    pub active_entries: TAILQ_ENTRY_active_entries,
    pub timeouts_entries: TAILQ_ENTRY_timeouts_entries,
    pub base: *mut sudo_event_base,
    pub fd: libc::c_int,
    pub events: libc::c_short,
    pub revents: libc::c_short,
    pub flags: libc::c_short,
    pub pfd_idx: libc::c_short,
    pub callback: sudo_ev_callback_t,
    pub timeout: timespec,
    pub closure: *mut libc::c_void,
}
pub type sudo_ev_callback_t =
    Option<unsafe extern "C" fn(libc::c_int, libc::c_int, *mut libc::c_void) -> ()>;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct TAILQ_ENTRY_sudo_event {
    pub tqe_next: *mut sudo_event,
    pub tqe_prev: *mut *mut sudo_event,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct TAILQ_ENTRY_active_entries {
    pub tqe_next: *mut sudo_event,
    pub tqe_prev: *mut *mut sudo_event,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct TAILQ_ENTRY_timeouts_entries {
    pub tqe_next: *mut sudo_event,
    pub tqe_prev: *mut *mut sudo_event,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct sudo_event_base {
    pub events: sudo_event_list,
    pub active: sudo_event_list,
    pub timeouts: sudo_event_list,
    pub signal_event: sudo_event,
    pub signals: [sudo_event_list; NSIG as usize],
    pub orig_handlers: [*mut sigaction; NSIG as usize],
    pub siginfo: [*mut siginfo_t; NSIG as usize],
    pub signal_pending: [sig_atomic_t; NSIG as usize],
    pub signal_caught: sig_atomic_t,
    pub num_handlers: libc::c_int,
    pub signal_pipe: [libc::c_int; 2],
    pub pfds: *mut pollfd,
    pub pfd_max: libc::c_int,
    pub pfd_high: libc::c_int,
    pub pfd_free: libc::c_int,
    pub flags: libc::c_uint,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct sudo_event_list {
    pub tqh_first: *mut sudo_event,
    pub tqh_last: *mut *mut sudo_event,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct sigaction {
    pub __sigaction_handler: Signal_handler,
    pub sa_mask: __sigset_t,
    pub sa_flags: libc::c_int,
    pub sa_restorer: Option<unsafe extern "C" fn() -> ()>,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct __sigset_t {
    pub __val: [libc::c_ulong; 16],
}
pub type sigset_t = __sigset_t;
#[derive(Copy, Clone)]
#[repr(C)]
pub union Signal_handler {
    pub sa_handler: __sighandler_t,
    pub sa_sigaction:
        Option<unsafe extern "C" fn(libc::c_int, *mut siginfo_t, *mut libc::c_void) -> ()>,
}
pub type __sighandler_t = Option<unsafe extern "C" fn(libc::c_int) -> ()>;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct siginfo_t {
    pub si_signo: libc::c_int,
    pub si_errno: libc::c_int,
    pub si_code: libc::c_int,
    pub __pad0: libc::c_int,
    pub _sifields: siginfo_t_u,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub union siginfo_t_u {
    pub _pad: [libc::c_int; 28],
    pub _kill: _kill_s,
    pub _timer: _timer_s,
    pub _rt: _rt_s,
    pub _sigchld: _sigchld_s,
    pub _sigfault: _sigfault_s,
    pub _sigpoll: _sigpoll_s,
    pub _sigsys: _sigsys_s,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct _kill_s {
    pub si_pid: __pid_t,
    pub si_uid: __uid_t,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct _timer_s {
    pub si_tid: libc::c_int,
    pub si_overrun: libc::c_int,
    pub si_sigval: __sigval_t,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub union sigval {
    pub sival_int: libc::c_int,
    pub sival_ptr: *mut libc::c_void,
}
pub type __sigval_t = sigval;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct _rt_s {
    pub si_pid: __pid_t,
    pub si_uid: __uid_t,
    pub si_sigval: __sigval_t,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct _sigchld_s {
    pub si_pid: __pid_t,
    pub si_uid: __uid_t,
    pub si_status: libc::c_int,
    pub si_utime: __clock_t,
    pub si_stime: __clock_t,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct _sigfault_s {
    pub si_addr: *mut libc::c_void,
    pub si_addr_lsb: libc::c_short,
    pub _bounds: _bounds_u,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub union _bounds_u {
    pub _addr_bnd: _addr_bnd_s,
    pub _pkey: __uint32_t,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct _addr_bnd_s {
    pub _lower: *mut libc::c_void,
    pub _upper: *mut libc::c_void,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct _sigpoll_s {
    pub si_band: libc::c_long,
    pub si_fd: libc::c_int,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct _sigsys_s {
    pub _call_addr: *mut libc::c_void,
    pub _syscall: libc::c_int,
    pub _arch: libc::c_uint,
}

#[derive(Copy, Clone)]
#[repr(C)]
pub struct timeval {
    pub tv_sec: __time_t,
    pub tv_usec: __suseconds_t,
}

#[derive(Copy, Clone)]
#[repr(C)]
pub struct _IO_FILE {
    pub _flags: libc::c_int,
    pub _IO_read_ptr: *mut libc::c_char,
    pub _IO_read_end: *mut libc::c_char,
    pub _IO_read_base: *mut libc::c_char,
    pub _IO_write_base: *mut libc::c_char,
    pub _IO_write_ptr: *mut libc::c_char,
    pub _IO_write_end: *mut libc::c_char,
    pub _IO_buf_base: *mut libc::c_char,
    pub _IO_buf_end: *mut libc::c_char,
    pub _IO_save_base: *mut libc::c_char,
    pub _IO_backup_base: *mut libc::c_char,
    pub _IO_save_end: *mut libc::c_char,
    pub _markers: *mut _IO_marker,
    pub _chain: *mut _IO_FILE,
    pub _fileno: libc::c_int,
    pub _flags2: libc::c_int,
    pub _old_offset: __off_t,
    pub _cur_column: libc::c_ushort,
    pub _vtable_offset: libc::c_schar,
    pub _shortbuf: [libc::c_char; 1],
    pub _lock: *mut libc::c_void,
    pub _offset: __off64_t,
    pub _codecvt: *mut _IO_codecvt,
    pub _wide_data: *mut _IO_wide_data,
    pub _freeres_list: *mut _IO_FILE,
    pub _freeres_buf: *mut libc::c_void,
    pub __pad5: size_t,
    pub _mode: libc::c_int,
    pub _unused2: [libc::c_char; 20],
}

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct _IO_marker {
    _unused: [u8; 0],
}

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct _IO_codecvt {
    _unused: [u8; 0],
}

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct _IO_wide_data {
    _unused: [u8; 0],
}

#[derive(Copy, Clone)]
#[repr(C)]
pub struct stat {
    pub st_dev: __dev_t,
    pub st_ino: __ino_t,
    #[cfg(target_arch = "x86_64")]
    pub st_nlink: __nlink_t,
    pub st_mode: __mode_t,
    #[cfg(not(target_arch = "x86_64"))]
    pub st_nlink: __nlink_t,
    pub st_uid: __uid_t,
    pub st_gid: __gid_t,
    #[cfg(target_arch = "x86_64")]
    pub __pad0: libc::c_int,
    pub st_rdev: __dev_t,
    #[cfg(not(target_arch = "x86_64"))]
    pub __pad1: __dev_t,
    pub st_size: __off_t,
    pub st_blksize: __blksize_t,
    #[cfg(not(target_arch = "x86_64"))]
    pub __pad2: libc::c_int,
    pub st_blocks: __blkcnt_t,
    pub st_atim: timespec,
    pub st_mtim: timespec,
    pub st_ctim: timespec,
    #[cfg(target_arch = "x86_64")]
    pub __glibc_reserved: [__syscall_slong_t; 3],
    #[cfg(not(target_arch = "x86_64"))]
    pub __glibc_reserved: [libc::c_int; 2],
}

#[derive(Copy, Clone)]
#[repr(C)]
pub struct sudo_debug_file {
    pub entries: sudo_debug_file_list,
    pub debug_file: *mut libc::c_char,
    pub debug_flags: *mut libc::c_char,
}

#[derive(Copy, Clone)]
#[repr(C)]
pub struct sudo_debug_file_list {
    pub tqe_next: *mut sudo_debug_file,
    pub tqe_prev: *mut *mut sudo_debug_file,
}

#[derive(Copy, Clone)]
#[repr(C)]
pub struct sudo_conf_debug_file_list {
    pub tqh_first: *mut sudo_debug_file,
    pub tqh_last: *mut *mut sudo_debug_file,
}

#[derive(Copy, Clone)]
#[repr(C)]
pub struct winsize {
    pub ws_row: libc::c_ushort,
    pub ws_col: libc::c_ushort,
    pub ws_xpixel: libc::c_ushort,
    pub ws_ypixel: libc::c_ushort,
}

#[derive(Copy, Clone)]
#[repr(C)]
pub struct dirent {
    pub d_ino: __ino_t,
    pub d_off: __off_t,
    pub d_reclen: libc::c_ushort,
    pub d_type: libc::c_uchar,
    pub d_name: [libc::c_char; 256],
}

#[derive(Copy, Clone)]
#[repr(C)]
pub union TMP_T {
    pub __u6_addr8: [libc::c_uchar; 16],
    pub __u6_addr16: [libc::c_ushort; 8],
    pub __u6_addr32: [libc::c_uint; 4],
}

#[derive(Copy, Clone)]
#[repr(C)]
pub struct in6_addr {
    pub __in6_u: TMP_T,
}

#[derive(Copy, Clone)]
#[repr(C)]
pub struct in_addr {
    pub s_addr: in_addr_t,
}

//add by bgz
//orig_c: DPRINTF1("STRING.....",base);
#[macro_export]
macro_rules! dprintf1 {
    ($fmt:expr, $($arg:tt)*) => {{
        sudo_debug_printf2_v1(
            get_function_name!(),
            get_file_name!(),
            line!() as libc::c_int,
            (5) | sudo_debug_subsys,
            $fmt,
            $($arg)*
            );
        if ldap_conf.debug >= 1 {
            sudo_warnx_nodebug_v1(
                $fmt,
                $($arg)*
            );
        }
    }};
}

//orig_c: DPRINTF2("STRING.....",base);
#[macro_export]
macro_rules! dprintf2 {
    ($fmt:expr, $($arg:tt)*) => {{
        sudo_debug_printf2_v1(
            get_function_name!(),
            get_file_name!(),
            line!() as libc::c_int,
            (6) | sudo_debug_subsys,
            $fmt,
            $($arg)*
            );
        if ldap_conf.debug >= 2 {
            sudo_warnx_nodebug_v1(
                $fmt,
                $($arg)*
            );
        }
    }};
}
//end of bgz

#[derive(Copy, Clone)]
#[repr(C)]
pub struct group {
    pub gr_name: *mut libc::c_char,
    pub gr_passwd: *mut libc::c_char,
    pub gr_gid: __gid_t,
    pub gr_mem: *mut *mut libc::c_char,
}

#[derive(Copy, Clone)]
#[repr(C)]
pub struct sudo_conv_callback {
    pub version: libc::c_uint,
    pub closure: *mut libc::c_void,
    pub on_suspend: sudo_conv_callback_fn_t,
    pub on_resume: sudo_conv_callback_fn_t,
}

#[derive(Copy, Clone)]
#[repr(C)]
pub struct policy_plugin {
    pub type_0: libc::c_uint,
    pub version: libc::c_uint,
    pub open: Option<
        unsafe extern "C" fn(
            libc::c_uint,
            sudo_conv_t,
            sudo_printf_t,
            *const *mut libc::c_char,
            *const *mut libc::c_char,
            *const *mut libc::c_char,
            *const *mut libc::c_char,
        ) -> libc::c_int,
    >,
    pub close: Option<unsafe extern "C" fn(libc::c_int, libc::c_int) -> ()>,
    pub show_version: Option<unsafe extern "C" fn(libc::c_int) -> libc::c_int>,
    pub check_policy: Option<
        unsafe extern "C" fn(
            libc::c_int,
            *const *mut libc::c_char,
            *mut *mut libc::c_char,
            *mut *mut *mut libc::c_char,
            *mut *mut *mut libc::c_char,
            *mut *mut *mut libc::c_char,
        ) -> libc::c_int,
    >,
    pub list: Option<
        unsafe extern "C" fn(
            libc::c_int,
            *const *mut libc::c_char,
            libc::c_int,
            *const libc::c_char,
        ) -> libc::c_int,
    >,
    pub validate: Option<unsafe extern "C" fn() -> libc::c_int>,
    pub invalidate: Option<unsafe extern "C" fn(libc::c_int) -> ()>,
    pub init_session:
        Option<unsafe extern "C" fn(*mut passwd, *mut *mut *mut libc::c_char) -> libc::c_int>,
    pub register_hooks: Option<
        unsafe extern "C" fn(
            libc::c_int,
            Option<unsafe extern "C" fn(*mut sudo_hook) -> libc::c_int>,
        ) -> (),
    >,
    pub deregister_hooks: Option<
        unsafe extern "C" fn(
            libc::c_int,
            Option<unsafe extern "C" fn(*mut sudo_hook) -> libc::c_int>,
        ) -> (),
    >,
}

#[derive(Copy, Clone)]
#[repr(C)]
pub struct sudo_conv_message {
    pub msg_type: libc::c_int,
    pub timeout: libc::c_int,
    pub msg: *const libc::c_char,
}

#[derive(Copy, Clone)]
#[repr(C)]
pub struct sudo_conv_reply {
    pub reply: *mut libc::c_char,
}

#[derive(Copy, Clone)]
#[repr(C)]
pub struct sudo_hook {
    pub hook_version: libc::c_uint,
    pub hook_type: libc::c_uint,
    pub hook_fn: sudo_hook_fn_t,
    pub closure: *mut libc::c_void,
}

#[derive(Copy, Clone)]
#[repr(C)]
pub struct passwd {
    pub pw_name: *mut libc::c_char,
    pub pw_passwd: *mut libc::c_char,
    pub pw_uid: __uid_t,
    pub pw_gid: __gid_t,
    pub pw_gecos: *mut libc::c_char,
    pub pw_dir: *mut libc::c_char,
    pub pw_shell: *mut libc::c_char,
}

#[derive(Copy, Clone)]
#[repr(C)]
pub struct iovec {
    pub iov_base: *mut libc::c_void,
    pub iov_len: size_t,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct plugin_info {
    pub entries: C2RustUnnamed_1,
    pub path: *mut libc::c_char,
    pub symbol_name: *mut libc::c_char,
    pub options: *mut *mut libc::c_char,
    pub lineno: libc::c_uint,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_1 {
    pub tqe_next: *mut plugin_info,
    pub tqe_prev: *mut *mut plugin_info,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct plugin_info_list {
    pub tqh_first: *mut plugin_info,
    pub tqh_last: *mut *mut plugin_info,
}

#[derive(Copy, Clone)]
#[repr(C)]
pub struct option {
    pub name: *const libc::c_char,
    pub has_arg: libc::c_int,
    pub flag: *mut libc::c_int,
    pub val: libc::c_int,
}

//下面的三个值，只用于初始化变量时调用，不会修改值。
pub const sb_all_arch: stat = stat {
    st_dev: 0,
    st_ino: 0,
    st_nlink: 0,
    st_mode: 0,
    st_uid: 0,
    st_gid: 0,
    #[cfg(target_arch = "x86_64")]
    __pad0: 0,
    st_rdev: 0,
    #[cfg(not(target_arch = "x86_64"))]
    __pad1: 0,
    st_size: 0,
    st_blksize: 0,
    #[cfg(not(target_arch = "x86_64"))]
    __pad2: 0,
    st_blocks: 0,
    st_atim: timespec {
        tv_sec: 0,
        tv_nsec: 0,
    },
    st_mtim: timespec {
        tv_sec: 0,
        tv_nsec: 0,
    },
    st_ctim: timespec {
        tv_sec: 0,
        tv_nsec: 0,
    },
    #[cfg(target_arch = "x86_64")]
    __glibc_reserved: [0; 3],
    #[cfg(not(target_arch = "x86_64"))]
    __glibc_reserved: [0; 2],
};

#[cfg(target_arch = "x86_64")]
pub const xstat_flag: libc::c_int = 1;

#[cfg(not(target_arch = "x86_64"))]
pub const xstat_flag: libc::c_int = 0;
